package com.skyworth.skymanualview;
import com.skyworth.skymanual.R;
import com.skyworth.skymanualActivity.GuideListActivity;
import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class BaseItemView extends MetroView {
	private RelativeLayout layout;
	private int type;
	private Context mContext;
	private ImageView imageView;
	private TextView itemName;
    private int height;
	private float tSize = 40*GuideListActivity.DIV_W /GuideListActivity.density;
	private int index;
	public BaseItemView(Context context, int w, int h, int index, int type) {
		super(context, w, h);
		this.type = type;
		this.index=index;
		height = h;
		mContext = context;
		initView();
	}
	private void initView() {
		layout = new RelativeLayout(mContext);
		imageView = new ImageView(mContext);
		itemName = new TextView(mContext);		
		itemName.setSingleLine(true);
		itemName.setEllipsize(TextUtils.TruncateAt.MARQUEE);
		itemName.setTextColor(Color.WHITE);
		itemName.setTextSize(tSize);		
		if (type == 1) {
			RelativeLayout.LayoutParams params_name = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			itemName.setTextSize(tSize);
			params_name.addRule(RelativeLayout.CENTER_HORIZONTAL);
		    params_name.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
		    params_name.bottomMargin=(int)(height/6);
			layout.addView(itemName,params_name);
			
			RelativeLayout.LayoutParams params_image=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
			params_image.addRule(RelativeLayout.ALIGN_PARENT_TOP);
			params_image.topMargin=(int)(height/10);
			params_image.addRule(RelativeLayout.CENTER_HORIZONTAL);
			layout.addView(imageView, params_image);		
		}else if(type==2){
			LinearLayout.LayoutParams params_name = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			itemName.setTextSize(tSize);
			params_name.gravity = Gravity.CENTER_HORIZONTAL;
			itemName.setLayoutParams(params_name);
			LinearLayout.LayoutParams params_image = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			params_image.gravity = Gravity.CENTER;
		    params_image.topMargin=height/3;
			layout.addView(imageView, params_image);
			layout.addView(itemName);
		} else {
			
		}		
		this.setViewContent(layout);		
		setPageDefautData();
	}

	public void setBackColor_test(){
		layout.setBackgroundColor(Color.RED);
	}
	public void setBackColor(int color){
		layout.setBackgroundResource(color);
	}
	//图标
	private void setPageDefautData(){
    	   if(index==1){
    		   itemName.setText("基本操作");
    		   imageView.setImageResource(R.drawable.icon_common);
    	   }else if(index==2){
    		   imageView.setImageResource(R.drawable.icon_setting);
    		   itemName.setText("设置");
    	   }else if(index==3){
    		   imageView.setImageResource(R.drawable.ico_sharing);
    		   itemName.setText("多屏互动");
    	   }else if(index==4){
    		   imageView.setImageResource(R.drawable.icon_play);
    		   itemName.setText("娱乐应用");
    	   }else if(index==5){
    		   imageView.setImageResource(R.drawable.icon_admin);
    		   itemName.setText("账户注册");
    	   }else if(index==6){
    		   imageView.setImageResource(R.drawable.ico_movie);
    		   itemName.setText("影视");
    	   }else if(index==7){
    		   imageView.setImageResource(R.drawable.icon_media);
    		   itemName.setText("媒体播放");
    	   }else if(index==8){
    		   imageView.setImageResource(R.drawable.ico_question);
    		   itemName.setText("疑难解答");
    	   }
       
       }
   
}
